<template>
  <Layout class="p-5 bg-white">
    <Form
      class="p-5"
      :model="Interview.student"
      :rules="ruleValidate"
      :label-width="155"
    >
      <Row>
        <Col span="8" push="2">
          <FormItem class="w-100" label="姓名" prop="name">
            <Input v-model="Interview.student.name"></Input>
          </FormItem>
          <FormItem class="w-100" label="手机号" prop="tel">
            <Input v-model="Interview.student.tel"></Input>
          </FormItem>
          <FormItem class="w-100" label="备注">
            <Input v-model="Interview.interview.des"></Input>
          </FormItem>
          <!-- <FormItem class="w-100" label="接待者">
            <Input v-model="Interview.interview.autor"></Input>
          </FormItem> -->
          <FormItem class="w-100" label="到访时间">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              :value="Interview.interview.dateTime"
              class="w-100"
              type="datetime"
              @on-change="interviewTime"
              placeholder="到访时间"
            >
            </Date-picker>
          </FormItem>
          <FormItem class="w-100" label="来访有效开关">
            <i-switch v-model="Interview.interview.flg"></i-switch>
          </FormItem>
          <FormItem class="w-100" label="应聘职位">
            <Input v-model="Interview.interview.ypzw"></Input>
          </FormItem>
          <FormItem class="w-100" label="线索来源">
            <Select v-model="Interview.resource.source" filterable clearable>
              <Option v-for="item in orsourceList" :value="item.value"
                >{{ item.label }}
              </Option>
            </Select>
          </FormItem>
          <FormItem class="w-100" label="线索状态">
            <Input v-model="Interview.resource.statu"></Input>
          </FormItem>
          <FormItem class="w-100" label="从事过的工作">
            <Input v-model="Interview.resource.csgz"></Input>
          </FormItem>
          <FormItem class="w-100" label="投递公司名称">
            <Input v-model="Interview.resource.tdgsmc"></Input>
          </FormItem>
          <!-- <FormItem class="w-100" label="添加人">
            <Input v-model="Interview.resource.cu"></Input>
          </FormItem> -->
          <FormItem class="w-100" label="身份证ID">
            <Input v-model="Interview.student.secId"></Input>
          </FormItem>
          <FormItem class="w-100" label="身份证正面">
            <Input v-model="Interview.student.secFrontUrl"></Input>
          </FormItem>
          <FormItem class="w-100" label="身份证反面">
            <Input v-model="Interview.student.secBackUrl"></Input>
          </FormItem>
          <FormItem class="w-100" label="身份证手持">
            <Input v-model="Interview.student.secHandleUrl"></Input>
          </FormItem>
        </Col>
        <Col span="8" push="3">
          <FormItem class="w-100" label="银行账户">
            <Input v-model="Interview.student.account"></Input>
          </FormItem>
          <FormItem class="w-100" label="银行预留电话">
            <Input v-model="Interview.student.accountTel"></Input>
          </FormItem>
          <FormItem class="w-100" label="联系地址">
            <Input v-model="Interview.student.address"></Input>
          </FormItem>
          <FormItem class="w-100" label="邮件">
            <Input v-model="Interview.student.email"></Input>
          </FormItem>
          <FormItem class="w-100" label="学历">
            <Input v-model="Interview.student.degree"></Input>
          </FormItem>
          <FormItem class="w-100" label="专业">
            <Input v-model="Interview.student.major"></Input>
          </FormItem>
          <FormItem class="w-100" label="毕业院校">
            <Input v-model="Interview.student.graduate"></Input>
          </FormItem>
          <FormItem class="w-100" label="生日">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              :value="Interview.student.birth"
              class="w-100"
              type="datetime"
              @on-change="birth"
              placeholder="生日"
            >
            </Date-picker>
          </FormItem>
          <FormItem class="w-100" label="毕业时间">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              :value="Interview.student.graduateTime"
              class="w-100"
              type="datetime"
              @on-change="graduateTime"
              placeholder="毕业时间"
            >
            </Date-picker>
          </FormItem>
          <FormItem class="w-100" label="资料备注">
            <Input v-model="Interview.resourceRecord.comment"></Input>
          </FormItem>
          <FormItem class="w-100" label="上传的文件或图片路径">
            <Input v-model="Interview.resourceRecord.content"></Input>
          </FormItem>
          <FormItem class="w-100" label="预约试听时间">
            <Date-picker
              :disabled="isReservationTry"
              format="yyyy-MM-dd HH:mm:ss"
              :value="Interview.reservationTry.datetime"
              class="w-100"
              type="datetime"
              @on-change="reservationTryTime"
              placeholder="预约试听时间"
            >
            </Date-picker>
          </FormItem>
          <FormItem class="w-100" label="预约回访时间">
            <Date-picker
              :disabled="isReservationBackview"
              format="yyyy-MM-dd HH:mm:ss"
              :value="Interview.reservationBackview.datetime"
              class="w-100"
              type="datetime"
              @on-change="reservationBackviewTime"
              placeholder="预约回访时间"
            >
            </Date-picker>
          </FormItem>
          <FormItem>
            <Button @click="submit" type="primary">提交</Button>
            <Button @click="cancel" style="margin-left: 8px">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
	<Loadding v-bind:loadinghuan="isSpinShow"></Loadding>
  </Layout>
</template>
<script>
export default {
  data() {
    return {
	  isSpinShow: false,
      ruleValidate: {
        name: [
          {
            required: true,
            message: '姓名不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
        tel: [
          {
            required: true,
            message: '电话号码不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
      },
      Interview: {
        interview: {
          id: '19',
          autor: '3',
          dateTime: '2021-06-01 00:01:00',
          flg: 0,
        },
        resource: {
          id: '14',
          source: '线索来源',
          ypzw: '应聘职位',
          csgz: '从事过的工作',
          tdgsmc: '投递公司名称',
          autor: '3',
          bz: '备注',
        },
        student: {
          id: '17',
          name: '学生姓名',
          secId: '身份证ID',
          secFrontUrl: '身份证正面',
          secBackUrl: '身份证反面',
          secHandleUrl: '身份证手持',
          tel: '联系电话',
          account: '银行账户',
          accountTel: '银行预留电话',
          address: '联系地址',
          email: '邮件',
          degree: '学历',
          major: '专业',
          graduate: '毕业院校',
          birth: '2021-06-01 00:01:00',
          graduateTime: '2021-06-01 00:01:00',
        },
        resourceRecord: {
          id: '12',
          comment: '资料备注',
          autor: '7',
          content: '上传的文件或图片路径',
        },
        reservationBackview: {
          id: '5',
          autor: '7',
          datetime: '2021-06-01 00:01:00',
        },
        reservationTry: {
          id: '5',
          autor: '7',
          datetime: '2021-06-01 00:01:00',
        },
      },
      interviewId: '',
      isReservationTry: false,
      isReservationBackview: false,
      orsourceList: [
        { value: '58同城', label: '58同城' },
        { value: '智联招聘', label: '智联招聘' },
        { value: '前程无忧', label: '前程无忧' },
        { value: 'boss直聘', label: 'boss直聘' },
        { value: '拉勾网', label: '拉勾网' },
        { value: '51job', label: '51job' },
        { value: '其他', label: '其他' },
      ],
    }
  },
  methods: {
    birth(change) {
      this.Interview.student.birth = change
    },
    graduateTime(change) {
      this.Interview.student.graduateTime = change
    },
    reservationBackviewTime(change) {
      this.Interview.reservationBackview.datetime = change
    },
    reservationTryTime(change) {
      this.Interview.reservationTry.datetime = change
    },
    interviewTime(change) {
      this.Interview.interview.dateTime = change
    },
    cancel: function() {
      this.$tabs.close({ to: '/interview' })
    },
    submit: function() {
      if (this.$data.Interview.student.name.trim().length === 0) {
        this.message.error('账户名必须输入')
		return
      }
      if (this.$data.Interview.student.name.indexOf(' ') > -1) {
        this.message.error('账户名中不能有空格')
        return
      }
      if (this.$data.Interview.student.tel.trim().length === 0) {
        this.message.error('电话号必须输入')
		return
      }
      if (this.$data.Interview.student.tel.indexOf(' ') > -1) {
        this.message.error('电话号码中不能有空格')
        return
      }
      let self = this
      let param = {
        'interview.id': this.$data.Interview.interview.id,
        'interview.des': this.$data.Interview.interview.des,
        'interview.autor': this.$data.Interview.interview.autor,
        'interview.ypzw': this.$data.Interview.interview.ypzw,
        'interview.dateTime': this.$data.Interview.interview.dateTime,
        'interview.flg': this.$data.Interview.interview.flg,

        'resource.id': this.$data.Interview.resource.id,
        'resource.source': this.$data.Interview.resource.source,
        'resource.csgz': this.$data.Interview.resource.csgz,
        'resource.tdgsmc': this.$data.Interview.resource.tdgsmc,
        'resource.cu': this.$data.Interview.resource.cu,
        'resource.statu': this.$data.Interview.resource.statu,

        'student.id': this.$data.Interview.student.id,
        'student.name': this.$data.Interview.student.name,
        'student.tel': this.$data.Interview.student.tel,
        'student.secId': this.$data.Interview.student.secId,
        'student.secFrontUrl': this.$data.Interview.student.secFrontUrl,
        'student.secBackUrl': this.$data.Interview.student.secBackUrl,
        'student.secHandleUrl': this.$data.Interview.student.secHandleUrl,
        'student.account': this.$data.Interview.student.account,
        'student.accountTel': this.$data.Interview.student.accountTel,
        'student.address': this.$data.Interview.student.address,
        'student.email': this.$data.Interview.student.email,
        'student.degree': this.$data.Interview.student.degree,
        'student.major': this.$data.Interview.student.major,
        'student.graduate': this.$data.Interview.student.graduate,
        'student.birth': '' + this.$data.Interview.student.birth,
        'student.graduateTime': '' + this.$data.Interview.student.graduateTime,

        'resourceRecord.id': this.$data.Interview.resourceRecord.id,
        'resourceRecord.content': this.$data.Interview.resourceRecord.content,
        'resourceRecord.comment': this.$data.Interview.resourceRecord.comment,

        'reservationBackview.id': this.$data.Interview.reservationBackview.id,
        'reservationBackview.datetime': this.$data.Interview.reservationBackview
          .datetime,

        'reservationTry.id': this.$data.Interview.reservationTry.id,
        'reservationTry.datetime': this.$data.Interview.reservationTry.datetime,
      }
      this.isSpinShow = true
      this.http
        .put({
          url: '/interview',
          param: param,
        })
        .then((data) => {
		  this.isSpinShow = false
          this.$tabs.close({ to: '/interview' })
          self.message.info('修改成功')
        })
    },
    init: function() {
      this.searchInterview()
    },
    searchInterview: function() {
      let self = this
      this.http
        .get({
          url: `/interview/info/${this.$data.interviewId}`,
        })
        .then((data) => {
          self.Interview = data
          if (self.Interview.reservationTry.datetime == null) {
            self.isReservationTry = true
          }
          if (self.Interview.reservationBackview.datetime == null) {
            self.isReservationBackview = true
          }
        })
    },
  },

  created: function() {},
  mounted: function(row) {
    this.$data.interviewId = this.$route.params.row.interviewId
    this.init()
  },
  destroyed: function() {
    this.$router.push({
      name: 'interview',
    })
  },
}
</script>

<style></style>
